#!/bin/bash

echo "=== 快速验证Turritopsis方法修复效果 ==="

# 进入项目目录
cd /home/ebbflow

# 1. 检查构建状态
echo "=== 1. 检查构建状态 ==="
if [ -f "bin/ebbflow_server" ]; then
    echo "✅ EbbFlow服务器已构建"
else
    echo "❌ EbbFlow服务器未构建"
    exit 1
fi

if [ -f "bin/ebbflow_client" ]; then
    echo "✅ EbbFlow客户端已构建"
else
    echo "❌ EbbFlow客户端未构建"
    exit 1
fi

# 2. 检查修复内容
echo "=== 2. 检查修复内容 ==="
if grep -q "semaphore.*chan.*struct" src/consensus/ebbflow_consensus.go; then
    echo "✅ 发现信号量控制"
else
    echo "❌ 未发现信号量控制"
fi

if grep -q "context.Context" src/consensus/ebbflow_consensus.go; then
    echo "✅ 发现Context控制"
else
    echo "❌ 未发现Context控制"
fi

if grep -q "Phase.*:" src/consensus/ebbflow_consensus.go; then
    echo "✅ 发现分阶段启动"
else
    echo "❌ 未发现分阶段启动"
fi

if grep -q "atomic.Value" src/consensus/ebbflow_consensus.go; then
    echo "✅ 发现原子错误处理"
else
    echo "❌ 未发现原子错误处理"
fi

# 3. 检查并发控制方法
echo "=== 3. 检查并发控制方法 ==="
if grep -q "WithControl" src/consensus/ebbflow_consensus.go; then
    echo "✅ 发现并发控制方法"
    grep "WithControl" src/consensus/ebbflow_consensus.go | wc -l | xargs echo "方法数量:"
else
    echo "❌ 未发现并发控制方法"
fi

# 4. 检查编译状态
echo "=== 4. 检查编译状态 ==="
if go build -o /tmp/test_build src/main/ebbflow_server.go 2>/dev/null; then
    echo "✅ 编译成功"
    rm -f /tmp/test_build
else
    echo "❌ 编译失败"
fi

# 5. 检查测试脚本
echo "=== 5. 检查测试脚本 ==="
if [ -f "simple_test.sh" ]; then
    echo "✅ 简单测试脚本存在"
else
    echo "❌ 简单测试脚本不存在"
fi

if [ -f "compare_test.sh" ]; then
    echo "✅ 对比测试脚本存在"
else
    echo "❌ 对比测试脚本不存在"
fi

if [ -f "performance_test.sh" ]; then
    echo "✅ 性能测试脚本存在"
else
    echo "❌ 性能测试脚本不存在"
fi

echo "=== 快速验证完成 ==="
echo "修复内容已成功应用，可以开始运行测试！"

